package drawer

import (
	"github.com/hajimehoshi/ebiten/v2"
	"image"
	"image/color"
)

var (
	ColorMagenta        = color.RGBA{R: 255, G: 0, B: 255, A: 255}
	ColorBlue           = color.RGBA{R: 0, G: 0, B: 255, A: 255}
	ColorLightBlue      = color.RGBA{R: 173, G: 216, B: 230, A: 255}
	ColorCornflowerBlue = color.RGBA{R: 100, G: 149, B: 237, A: 255}
	ColorRed            = color.RGBA{R: 255, G: 0, B: 0, A: 255}
	ColorGreen          = color.RGBA{R: 0, G: 255, B: 0, A: 255}
	ColorGold           = color.RGBA{R: 255, G: 215, B: 0, A: 255}
	ColorCyan           = color.RGBA{R: 0, G: 255, B: 255, A: 255}
	ColorOrange         = color.RGBA{R: 255, G: 165, B: 0, A: 255}
	ColorPurple         = color.RGBA{R: 128, G: 0, B: 128, A: 255}
	ColorBrown          = color.RGBA{R: 165, G: 42, B: 42, A: 255}
	ColorGray           = color.RGBA{R: 128, G: 128, B: 128, A: 255}
	ColorLightGray      = color.RGBA{R: 211, G: 211, B: 211, A: 255}
	ColorBlack          = color.RGBA{R: 0, G: 0, B: 0, A: 255}
	ColorWhite          = color.RGBA{R: 255, G: 255, B: 255, A: 255}
	ColorSnow           = color.RGBA{R: 255, G: 250, B: 250, A: 255}
	ColorBiege          = color.RGBA{R: 255, G: 255, B: 224, A: 255}
	ColorP              = color.RGBA{R: 200, G: 200, B: 200, A: 255}
)

var (
	whiteImage    = ebiten.NewImage(3, 3)
	whiteSubImage = whiteImage.SubImage(image.Rect(1, 1, 2, 2)).(*ebiten.Image)
)

func init() {
	b := whiteImage.Bounds()
	pix := make([]byte, 4*b.Dx()*b.Dy())
	for i := range pix {
		pix[i] = 0xff
	}
	whiteImage.WritePixels(pix)
}

func ColorTransparent(clr color.Color, a float64) color.Color {
	c := clr.(color.RGBA)
	return color.RGBA{R: c.R, G: c.G, B: c.B, A: uint8(float64(c.A) * a)}
}

func setColorToVertices(vs []ebiten.Vertex, clr color.Color) []ebiten.Vertex {
	r, g, b, a := clr.RGBA()

	for i := range vs {
		vs[i].SrcX = 1
		vs[i].SrcY = 1
		vs[i].ColorR = float32(r) / 0xffff
		vs[i].ColorG = float32(g) / 0xffff
		vs[i].ColorB = float32(b) / 0xffff
		vs[i].ColorA = float32(a) / 0xffff
	}

	return vs
}
